﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.Scheduling;
using MediatR;
using Scheduling.Api.Write.Application.Command.TeamCommand;
using Scheduling.Services.Teams;

namespace Scheduling.Api.Write.Application.CommandHandlers.TeamHandler
{
    public class TeamUpdCommandHandler : IRequestHandler<TeamUpdCommand, ApiResult<int>>
    {
        public TeamUpdCommandHandler(ITeamServices teams,IMapper mapper) 
        {
            Teams = teams;
            Mapper = mapper;
        }

        public ITeamServices Teams { get; }
        public IMapper Mapper { get; }

        public async Task<ApiResult<int>> Handle(TeamUpdCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Team>(request);
            return await Teams.UpdTeam(list);
        }
    }
}
